package com.zmzncs.lmtc.module.order.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zmzncs.lmtc.common.util.DateTimeUtil;
import com.zmzncs.lmtc.module.order.dao.OrderCompareResultDao;
import com.zmzncs.lmtc.module.order.dao.OrderHistoryDao;
import com.zmzncs.lmtc.module.order.dao.OrderInfoDao;
import com.zmzncs.lmtc.module.order.dao.OrderTradeRecordDao;
import com.zmzncs.lmtc.module.order.pojo.orderCompareResult.OrderCompareResult;
import com.zmzncs.lmtc.module.order.pojo.order_Info.OrderHistoryForm;
import com.zmzncs.lmtc.module.order.pojo.orderCompareResult.OrderCompareResultDTO;
import com.zmzncs.lmtc.module.order.pojo.order_history.OrderHistory;
import com.zmzncs.lmtc.module.order.service.OrderHistoryService;
import com.zmzncs.lmtc.module.park.dao.ParkInfoDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import java.util.Date;

/**
 * <p>
 * 财务-对账账单表 服务实现类
 * </p>
 *
 * @author
 * @since 2021-04-07
 */
@Service
public class OrderHistoryServiceImpl extends ServiceImpl<OrderHistoryDao, OrderHistory> implements OrderHistoryService {

    /** 数据库表*/
    private String schemaName;

    @Value("${orderHistory.schemaName}")
    public void setSchemaName(String schemaName) {
        this.schemaName = schemaName;
    }

    /**历史订单表名固定字段 */
    private String name = "order_history_";
    @Autowired
    OrderHistoryDao orderHistoryDao;
    @Autowired
    ParkInfoDao parkInfoDao;
    @Autowired
    OrderInfoDao orderInfoDao;
    @Autowired
    OrderCompareResultDao orderCompareResultDao;
    @Autowired
    OrderTradeRecordDao orderTradeRecordDao;
    @Override
    public IPage<OrderCompareResultDTO> selectTableOrderHistory(OrderHistoryForm form) {
        Page page = new Page<>(form.getCurrent(), form.getSize());
        IPage<OrderCompareResultDTO>  orderErrorResultDTOS  =
                orderCompareResultDao.list(page);
        return orderErrorResultDTOS;
    }

    @Override
    public int orderResultPass(Long id, int status, String passMsg) {
        OrderCompareResult orderCompareResult = orderCompareResultDao.selectById(id);
        orderCompareResult.setIsPass(status);
        orderCompareResult.setPassMsg(passMsg);
        return orderCompareResultDao.updateById(orderCompareResult);
    }


    /** 获取完整表名*/
    public String getTableName(Date  day){
        if(day==null){
            return null;
        }
        String ymd = DateTimeUtil.convertYYYYMMDD(day);
        String tableName = name + ymd.substring(0, 6);
        return tableName;
    }



}
